home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / amiga / gui / prcgntn1.lha / Precognition / source / VScroller.c < prev    next >
C/C++ Source or Header  |  1992-12-23  |  11KB  |  400 lines

  1. /* ==========================================================================
  2. **
  3. **                         VScroller.c
  4. **
  5. ** ⌐1991 WILLISoft
  6. **
  7. ** ==========================================================================
  8. */
  9.  
  10. #include <stdio.h>
  11. #include "minmax.h"
  12. #include "VScroller.h"
  13. #include "VScrollerClass.h"
  14. #include "EmbossedGadgetClass.h"
  15. #include <proto/exec.h>
  16. #include <proto/intuition.h>
  17. #include <proto/graphics.h>
  18. #include "amigamem.h"
  19.  
  20. void VScroller_SetInteractorWindow( VScroller *self, pcgWindow *window )
  21. {
  22.    self->posr.IaWindow = window;
  23.    SetInteractorWindow( &self->vslider,   window );
  24.    SetInteractorWindow( &self->uparrow,   window );
  25.    SetInteractorWindow( &self->downarrow, window );
  26. }
  27.  
  28.  
  29.  
  30. void VScroller_CleanUp( VScroller *self )
  31. {
  32.    CleanUp( &self->vslider   );
  33.    CleanUp( &self->uparrow   );
  34.    CleanUp( &self->downarrow );
  35. }
  36.  
  37.  
  38. tPoint VScroller_SetLocation(  VScroller *self,
  39.                                PIXELS     LeftEdge,
  40.                                PIXELS     TopEdge )
  41. {
  42.  
  43.    Point Up_size, Slider_size;
  44.    Point Up_pos,  Down_pos;
  45.  
  46.  
  47.    Up_size     = Size( &self->uparrow );
  48.    Slider_size = Size( &self->vslider );
  49.  
  50.    SetLocation( &self->vslider, LeftEdge, TopEdge );
  51.  
  52.    Up_pos.x = LeftEdge;
  53.    Up_pos.y = TopEdge + Slider_size.y;
  54.    SetLocation( &self->uparrow, Up_pos.x, Up_pos.y );
  55.  
  56.    Down_pos.x = LeftEdge;
  57.    Down_pos.y = Up_pos.y + Up_size.y;
  58.    SetLocation( &self->downarrow, Down_pos.x, Down_pos.y );
  59.  
  60.    self->posr.Location.x = LeftEdge;
  61.    self->posr.Location.y = TopEdge;
  62.  
  63.    return Location( self );
  64. }
  65.  
  66.  
  67. tPoint VScroller_private_AskSize(  VScroller *self,
  68.                                    PIXELS     Width,
  69.                                    PIXELS     Height,
  70.                                    Point     *Up_size,
  71.                                    Point     *Down_size,
  72.                                    Point     *Slider_size )
  73. {
  74.    Point size;
  75.  
  76.    *Up_size   = AskSize( &self->uparrow,   0, 0 );
  77.    *Down_size = AskSize( &self->downarrow, 0, 0 );
  78.  
  79.    Slider_size->y = Height - (Up_size->y + Down_size->y);
  80.    Slider_size->x = MAX( Up_size->x, Down_size->x );
  81.  
  82.    *Slider_size = AskSize( &self->vslider, Slider_size->x, Slider_size->y );
  83.  
  84.    size.x = Slider_size->x;
  85.    size.y = Slider_size->y + Up_size->y + Down_size->y;
  86.  
  87.    return size;
  88. }
  89.  
  90.  
  91. tPoint VScroller_AskSize(  VScroller *self,
  92.                            PIXELS     Width,
  93.                            PIXELS     Height )
  94. {
  95.    Point Up_size, Down_size, Slider_size, size;
  96.  
  97.    size = VScroller_private_AskSize( self, Width, Height,
  98.             &Up_size, &Down_size, &Slider_size );
  99.  
  100.    return size;
  101. }
  102.  
  103.  
  104. tPoint VScroller_SetSize(  VScroller *self,
  105.                            PIXELS     Width,
  106.                            PIXELS     Height )
  107. {
  108.  
  109.    tPoint Up_size, Down_size, Slider_size, size;
  110.    tPoint pos;
  111.  
  112.    size = VScroller_private_AskSize( self, Width, Height,
  113.             &Up_size, &Down_size, &Slider_size );
  114.  
  115.    SetSize( &self->uparrow,   Up_size.x,   Up_size.y );
  116.    SetSize( &self->downarrow, Down_size.x, Down_size.y );
  117.    SetSize( &self->vslider,   Slider_size.x, Slider_size.y );
  118.  
  119.    /* Now must fix the positions of uparrow, down arrow. */
  120.  
  121.    pos = Location( self );
  122.    SetLocation( self, pos.x, pos.y );
  123.    self->posr.Size = size;
  124.  
  125.    AlignText( &self->vslider.eg.LabelText, Size(self) );
  126.  
  127.    return size;
  128. }
  129.  
  130.  
  131. void VScroller_Render( VScroller *self, RastPort *RPort )
  132. {
  133.    Render( &self->vslider,   RPort );
  134.    Render( &self->uparrow,   RPort );
  135.    Render( &self->downarrow, RPort );
  136. }
  137.  
  138.  
  139. Gadget *VScroller_FirstGadget( VScroller *self )
  140. {
  141.    return FirstGadget( &self->vslider );
  142. }
  143.  
  144.  
  145. USHORT VScroller_nGadgets( VScroller *self )
  146. {
  147.    return nGadgets( &self->vslider ) + nGadgets( &self->uparrow )
  148.       + nGadgets( &self->downarrow );
  149. }
  150.  
  151.  
  152. ULONG VScroller_IDCMPFlags( VScroller *self )
  153. {
  154.    return IDCMPFlags( &self->vslider )
  155.         | IDCMPFlags( &self->uparrow )
  156.         | IDCMPFlags( &self->downarrow );
  157. }
  158.  
  159. USHORT VScroller_ClaimEvent( VScroller *self, IntuiMessage *event )
  160. {
  161.    return ClaimEvent( &self->vslider,   event )
  162.         | ClaimEvent( &self->uparrow,   event )
  163.         | ClaimEvent( &self->downarrow, event );
  164.  
  165. }
  166.  
  167. BOOL VScroller_EnableIactor( VScroller *self, BOOL enable )
  168. {
  169.    EnableIactor( &self->vslider,   enable );
  170.    EnableIactor( &self->uparrow,   enable );
  171.    EnableIactor( &self->downarrow, enable );
  172.    return enable;
  173. }
  174.  
  175. USHORT VScroller_Respond( VScroller *self, IntuiMessage *event )
  176. {
  177.    USHORT vsr = 0; /* Vertical slider response  */
  178.    USHORT uar = 0; /* uparrow response          */
  179.    USHORT dar = 0; /* down arrow response       */
  180.  
  181.    vsr = Respond( &self->vslider, event );
  182.  
  183.    if (! (vsr & CONSUMED_EVENT))
  184.    {
  185.       /* Up Arrow */
  186.       uar = Respond( &self->uparrow, event );
  187.  
  188.       if ((uar & CHANGED_STATE) && (Value(&self->uparrow)))
  189.       {
  190.          SlideLower( &self->vslider );
  191.       }
  192.  
  193.       if (!(uar & CONSUMED_EVENT))
  194.       {
  195.          /* Down Arrow */
  196.          dar = Respond( &self->downarrow, event );
  197.          if ((dar & CHANGED_STATE) && (Value(&self->downarrow)))
  198.          {
  199.             SlideHigher( &self->vslider );
  200.          }
  201.       }
  202.    }
  203.  
  204.    return vsr | uar | dar;
  205. }
  206.  
  207.  
  208. void VScroller_Refresh( VScroller *self )
  209. {
  210.    pcgWindow *window;
  211.  
  212.    if (window = InteractorWindow(self))
  213.    {
  214.       Refresh( &self->vslider   );
  215.       Refresh( &self->uparrow   );
  216.       Refresh( &self->downarrow );
  217.    }
  218. }
  219.  
  220. USHORT VScroller_Value( VScroller *self )
  221. {
  222.    return Value( &self->vslider );
  223. }
  224.  
  225. USHORT VScroller_SetValue( VScroller *self, USHORT position )
  226. {
  227.    return SetValue( &self->vslider, position );
  228. }
  229.  
  230. USHORT VScroller_KnobSize( VScroller *self )
  231. {
  232.    return KnobSize( &self->vslider );
  233. }
  234.  
  235. USHORT VScroller_SetKnobSize( VScroller *self, USHORT knobsize )
  236. {
  237.    return SetKnobSize( &self->vslider, knobsize );
  238. }
  239.  
  240. char *VScroller_Title( VScroller *self )
  241. {
  242.    return Title(&self->vslider);
  243. }
  244.  
  245. BOOL VScroller_SetTitle( VScroller *self,
  246.                          char      *title )
  247. {
  248.    SetTitle( &self->vslider, title );
  249.    AlignText( &self->vslider.eg.LabelText, Size(self) );
  250.  
  251.    return TRUE;
  252. }
  253.  
  254.  
  255. AlignInfo VScroller_TextAlignment( VScroller *self )
  256. {
  257.    return self->vslider.eg.LabelText.alignment;
  258. }
  259.  
  260. AlignInfo VScroller_SetTextAlignment( VScroller *self,
  261.                                            UBYTE     Flags,
  262.                                            BYTE      Xpad,
  263.                                            BYTE      Ypad )
  264. {
  265.    self->vslider.eg.LabelText.alignment.Flags = Flags;
  266.    self->vslider.eg.LabelText.alignment.Xpad  = Xpad;
  267.    self->vslider.eg.LabelText.alignment.Ypad  = Ypad;
  268.    AlignText( &self->vslider.eg.LabelText, Size(self) );
  269.    return self->vslider.eg.LabelText.alignment;
  270. }
  271.  
  272.  
  273. #ifdef BUILDER
  274. #include "BuilderMethods.h"
  275. #include "GraphicObject_Builder.h"
  276. #include "Positioner_Builder.h"
  277. #include "Positioner_coder.h"
  278.  
  279. struct BuilderMethods VScroller_bm;
  280.  
  281. VScroller *VScroller_New( VScroller *self )
  282. {
  283.    VScroller *new_vscroller = NULL;
  284.  
  285.    if (new_vscroller = (VScroller *) Amalloc(sizeof(VScroller)))
  286.    {
  287.       VScroller_Init( new_vscroller,   self->posr.Location.x, self->posr.Location.y,
  288.                       self->posr.Size.y,    self->Pens,
  289.                       Title(self) );
  290.       GiveItAName( new_vscroller );
  291.    }
  292.    return new_vscroller;
  293. }
  294.  
  295. #endif
  296.  
  297.  
  298. BOOL VScroller_elaborated = FALSE;
  299.  
  300. struct PositionerClass VScroller_Class;
  301.  
  302. void VScrollerClass_Init( struct PositionerClass *class )
  303. {
  304.    PositionerClass_Init( class );
  305.    class->isa                 = PositionerClass();
  306.    class->ClassName           = "VScroller";
  307. /*   class->New                 = VScroller_New;*/
  308.    class->CleanUp             = VScroller_CleanUp;
  309.    class->SetLocation         = VScroller_SetLocation;
  310.    class->AskSize             = VScroller_AskSize;
  311.    class->SetSize             = VScroller_SetSize;
  312.    class->SizeFlags           = GraphicObject_SizeFlagsY;
  313.    class->Render              = VScroller_Render;
  314.    class->SetInteractorWindow = VScroller_SetInteractorWindow;
  315.    class->FirstGadget         = VScroller_FirstGadget;
  316.    class->nGadgets            = VScroller_nGadgets;
  317.    class->IDCMPFlags          = VScroller_IDCMPFlags;
  318.    class->ClaimEvent          = VScroller_ClaimEvent;
  319.    class->Respond             = VScroller_Respond;
  320.    class->Refresh             = VScroller_Refresh;
  321.    class->EnableIactor              = VScroller_EnableIactor;
  322.    class->isEnabled           = EmbossedGadget_isEnabled;
  323.    class->Activate            = NULL;
  324.    class->isActive            = NULL;
  325.    class->SetKnobSize         = VScroller_SetKnobSize;
  326.    class->SetValue            = VScroller_SetValue;
  327.    class->KnobSize            = VScroller_KnobSize;
  328.    class->Value               = VScroller_Value;
  329.    class->Title               = VScroller_Title;
  330.    class->SetTitle            = VScroller_SetTitle;
  331.    class->TextAlignment       = VScroller_TextAlignment;
  332.    class->SetTextAlignment    = VScroller_SetTextAlignment;
  333. #ifdef BUILDER
  334.    go_InitBuilderMethods( &VScroller_bm );
  335.    VScroller_bm.New       = VScroller_New;
  336.    VScroller_bm.PropEdit  = Positioner_PropEdit;
  337.    VScroller_bm.WriteCode = Positioner_WriteCode;
  338.    class->BuilderMethods  = &VScroller_bm;
  339. #endif
  340.  
  341. }
  342.  
  343.  
  344. struct PositionerClass *VScrollerClass( void )
  345. {
  346.    if (! VScroller_elaborated)
  347.    {
  348.       VScrollerClass_Init( &VScroller_Class );
  349.       VScroller_elaborated = TRUE;
  350.    }
  351.  
  352.    return &VScroller_Class;
  353. }
  354.  
  355.  
  356.  
  357.  
  358. void VScroller_Init( VScroller  *self,
  359.                      PIXELS      LeftEdge,
  360.                      PIXELS      TopEdge,
  361.                      PIXELS      Height,
  362.                      pcg_3DPens  Pens,
  363.                      char       *label )
  364. {
  365.    Gadget *g;
  366.  
  367.    Positioner_Init(self);
  368.  
  369.    self->posr.isa           = VScrollerClass();
  370.    self->posr.Next          = NULL;
  371.    self->posr.PObjectName    = NULL;
  372.    self->posr.Location.x    = LeftEdge;
  373.    self->posr.Location.y    = TopEdge;
  374.    self->Pens               = Pens;
  375.  
  376.    /*
  377.    ** Initialize objects with dumb values, just so that they are now
  378.    ** proper objects.
  379.    */
  380.  
  381.    ArrowGadget_Init( &self->uparrow,   LeftEdge, TopEdge,
  382.       UpArrow, Pens );
  383.    ArrowGadget_Init( &self->downarrow, LeftEdge, TopEdge,
  384.       DownArrow, Pens );
  385.  
  386.    VSlider_Init( &self->vslider,       LeftEdge, TopEdge, 0, 0, Pens, NULL );
  387.  
  388.    self->vslider.eg.Next = &self->uparrow;
  389.    self->uparrow.Next    = &self->downarrow;
  390.  
  391.    SetSize( self, 0, Height );
  392.    SetTitle( self, label );
  393.    SetTextAlignment( self, tx_XCENTER | tx_BOTTOM | tx_OUTSIDE, STD_XPAD, STD_YPAD );
  394.  
  395.    /* Chain the gadgets together. */
  396.    g = FirstGadget( self );
  397.    ChainGadgets( g,  FirstGadget( &self->uparrow ) );
  398.    ChainGadgets( g,  FirstGadget( &self->downarrow ) );
  399. }
  400.